1
hq.labels = {

	AjaxUrl : '/ajax/get-labels.php',

	MetroId : null,

	labels: [],

	init: function() {
		this.MetroId = $j('#metroId').val();
		GEvent.addListener(hq.map.gMap, 'moveend', toolbox.delegate(this.getLabels, this));
		this.getLabels();
	},

	getLabels : function() {
		if(this.curTrans) {
			this.curTrans.abort();
			this.curTrans = null;
		}

		var bounds = hq.map.getBounds();

		this.curTrans = $j.ajax({
			url: this.AjaxUrl,
			data: {
				metroId : this.MetroId,
				minX: bounds.minX,
				maxX: bounds.maxX,
				minY: bounds.minY,
				maxY: bounds.maxY
			},
			dataType: 'json',
			success: toolbox.delegate(this.loadLabels, this)
		});
	},

	
        loadLabels : function( res ) {
                console.group( 'labels::loadLabels' );
		
                var len = this.labels.length;
                for( var i=0; i<len; i++) {
                        hq.map.gMap.removeOverlay( this.labels[i] );
                }
	console.info('Done removing overlays');
                this.labels = [];

                len = res.length;
                for( i=0; i<len; i++ ) {
			
                        var label = new ELabel( new GLatLng( res[i].y, res[i].x ), res[i].name1, 'spaceLabel' );
                        hq.map.gMap.addOverlay( label );
                        this.labels[ this.labels.length ] = label;
			console.info('Added overlay: ' + res[i].name1);


                        $j( label.div_ )
                                .click( toolbox.delegate( this.onLabel, this, res[i] ) );
         //                       .mouseover( toolbox.delegateNPA( this.onOverLabel, this, label, spaceItem, true ) )
           //                     .mouseout( toolbox.delegateNPA( this.onOutLabel, this, label, spaceItem, true ) );

                }


                console.groupEnd();
        },

	onLabel : function(evt, label) {
		hq.map.gMap.setCenter(new GLatLng(label.y, label.x), hq.spacePolygon.CensusLevel);
		
	},

	displayLabels : function(res) {
		for(var i in res) {
			var test = res[i].name1;
			var point = hq.map.gMap.fromLatLngToContainerPixel(new GLatLng(res[i].x, res[i].y));
		
			$j("<divi class='hqLabel'>" + res[i].name1 + "</div>").appendTo('#map').css({position: "absolute", top: point.y, left: point.x});
			
		}
	}


};

$j(document).ready(toolbox.delegate(hq.labels.init, hq.labels));

